package com.bdc.activity;

import com.bdc.R;
import com.bdc.service.BdcService;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class LoginActivity extends android.app.Activity {
	
	private BdcService bdcService ;
	private ProgressDialog progressDialog ;
	private LoginActivity self = this ;
	
	private PostExecutor verifyUserPostExecutor = new PostExecutor(){

		@Override
		public void postExecute(Object... objs) {
			Long userId = (Long)objs[0] ;
			progressDialog.dismiss() ;
			if(userId>0){
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setClassName(LoginActivity.this, MemorizeActivity.class.getName()) ;
				startActivity(intent) ;
			}else{
				//��ʾ��ͨ����֤
				Toast toast = Toast.makeText(LoginActivity.this, "��֤��ͨ��", Toast.LENGTH_SHORT) ;
				toast.show() ;
			}
		}
		
	} ;
	
	public Button.OnClickListener loginClickClickListener = new Button.OnClickListener(){
		public void onClick(View v) {
			//TODO ��ʾ��ȡ���ȡ������û�������
			progressDialog = ProgressDialog.show(LoginActivity.this, "", "������֤�����Ժ�...") ;
			bdcService.verifyUser("admin", "11111", verifyUserPostExecutor) ;
		}
	};
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        bdcService = BdcService.getInstance();
        
        findViewById(R.id.btnLogin).setOnClickListener(loginClickClickListener) ;
    }
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
    	MenuInflater menuInflater = getMenuInflater() ;
    	menuInflater.inflate(R.menu.desktop_menu, menu) ;
		return true;
	}
    
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){
			case R.id.menu_preference:
				Intent settingIntent = new Intent(self, SettingActivity.class);
				startActivity(settingIntent) ;
				return true ;
			case R.id.menu_about:
				
			default:
				return super.onOptionsItemSelected(item);
		}
	}
}
